import {Component, Input, OnInit} from '@angular/core';
import {CourseInfo} from "../student";
import {HttpService} from "../http.service";
import {ActivatedRoute} from "@angular/router";
import {Location} from "@angular/common";

@Component({
  selector: 'app-course',
  templateUrl: './course.component.html',
  styleUrls: ['./course.component.css']
})
export class CourseComponent implements OnInit {
  constructor( private httpService: HttpService,
               private route: ActivatedRoute,
               private location: Location,) { }
  courseInfo: CourseInfo[] = [];
  CourseInfo: CourseInfo[] = [];
  pageIndex = 1;
  pageSize = 10;
  total = 60;
  loading = true;
  changePage(): void {
    this.CourseInfo = this.courseInfo.slice((this.pageIndex - 1) * this.pageSize, (this.pageIndex) * this.pageSize);
  }
  getCourses(): void {
    this.httpService.getCourses().subscribe(
      res => {
        res.data.forEach(cou => {
          this.courseInfo = [...this.courseInfo];
          this.courseInfo.push( {
              courseid : cou.courseid,
              coursename : cou.coursename,
              credit : cou.credit,
              type : cou.type
            }
          );
        });
        this.CourseInfo = this.courseInfo.slice( 0 , 10);
        this.loading = false;
      }
    );
  }

  ngOnInit(): void {
    this.getCourses();
  }

}
